package com.softer.chengxin.traning.dao.provider;

import com.softer.chengxin.traning.entity.TraningDetail;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
 * @author wxr
 * @date 2019/1/19
 */
public class TraningDetailProvider {
    public String update(Map<String, Object> map) {
        StringBuilder sql = new StringBuilder(20);
        TraningDetail traingDetail = (TraningDetail) map.get("traningDetail");
        sql.append("update traning_detail set ");
        if (StringUtils.isNotBlank(traingDetail.getEndDate())) {
            sql.append("`end_date`=#{traningDetail.endDate},");
        }
        if (StringUtils.isNotBlank(traingDetail.getStartDate())) {
            sql.append("`start_date`=#{traningDetail.startDate},");
        }
        if (StringUtils.isNotBlank(traingDetail.getFileId())) {
            sql.append("`file_id`=#{traningDetail.fileId},");
        }
        if (StringUtils.isNotBlank(traingDetail.getRainingSubject())) {
            sql.append("`raining_subject`=#{traningDetail.rainingSubject},");
        }
        if (StringUtils.isNotBlank(traingDetail.getEduTrainingDep())) {
            sql.append("`edu_training_dep`=#{traningDetail.eduTrainingDep},");
        }
        if (StringUtils.isNotBlank(traingDetail.getRemark())) {
            sql.append("`remark`=#{traningDetail.remark},");
        }
        sql.append("update_time=#{traningDetail.updateTime} ");
        sql.append(" where id=#{traningDetail.id}");
        return sql.toString();
    }

    public String changeState(Map<String, Object> map) {
        StringBuilder sql = new StringBuilder(20);
        String id = (String) map.get("id");
        String recRemark = (String) map.get("recRemark");
        String state = (String) map.get("state");
        String name = (String) map.get("name");
        sql.append("update traning_detail set ");
        if (recRemark != null) {
            sql.append("rec_remark=#{recRemark},");
        }
        if (state.equals("1")||state.equals("0")) {
            sql.append("state=#{state}");
        } else {
            sql.append("state=#{state},");
            sql.append("rec_date=now(),");
            sql.append("rec_name=#{name}");
        }
        sql.append("where id=#{id}");
        return sql.toString();
    }
}
